package cn.cgg.delay;

import cn.cgg.Constants;
import com.alibaba.fastjson.JSON;
import io.netty.util.CharsetUtil;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;


import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

public class Producer {

    public static void main(String[] args) throws Exception{

        //创建producer实例
        DefaultMQProducer producer = new DefaultMQProducer("hello-world");
        //连接nameServer
        producer.setNamesrvAddr(Constants.NAME_SERVER_URL);
        //启动
        producer.start();
        //创建信息
        Message message = new Message("log-topic", "info_tag", "延迟消息".getBytes(RemotingHelper.DEFAULT_CHARSET));



        message.setDelayTimeLevel(3);
        //发送消息  并且接收返回结果
        SendResult sendResult = producer.send(message);
        System.out.println(LocalDateTime.now().toString());
        System.out.println(sendResult);
        //关闭资源
        producer.shutdown();
    }
}